package cn.itrip.trade.service.itripHotelOrder;

import cn.itrip.beans.pojo.ItripHotelOrder;
import cn.itrip.beans.pojo.ItripHotelRoom;
import cn.itrip.beans.pojo.ItripHotelTempStore;
import cn.itrip.beans.pojo.ItripTradeEnds;
import cn.itrip.common.BigDecimalUtil;
import cn.itrip.common.Constants;
import cn.itrip.common.EmptyUtils;
import cn.itrip.common.Page;
import cn.itrip.mapper.itripHotelOrder.ItripHotelOrderMapper;
import cn.itrip.mapper.itripHotelRoom.ItripHotelRoomMapper;
import cn.itrip.mapper.itripTradeEnds.ItripTradeEndsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.math.BigDecimal.ROUND_DOWN;

@Service
public class ItripHotelOrderServiceImpl implements ItripHotelOrderService {

    @Resource
    private ItripHotelOrderMapper itripHotelOrderMapper;

    @Resource
    private ItripTradeEndsMapper itripTradeEndsMapper;

    @Override
    public ItripHotelOrder getItripHotelOrderByOrderNo(String orderNo) throws Exception {
            Map map= new HashMap();
            map.put("orderNo",orderNo);
            List<ItripHotelOrder> itripHotelOrderList =itripHotelOrderMapper.getItripHotelOrderListByMap(map);
        return itripHotelOrderList.get(0);
    }

    @Override
    public void processOrderStauts(String orderNo, int payType, String tradeNo) throws Exception {
        ItripHotelOrder order = this.getItripHotelOrderByOrderNo(orderNo);
        order.setOrderStatus(2);
        order.setPayType(payType);
        //交易号
        order.setTradeNo(tradeNo);
        //执行sql
        itripHotelOrderMapper.updateItripHotelOrder(order);
        //对库存进行处理,这里通过异步请求处理 --- 消息队列---》表 代办事项表---》定时器定时扫描轮询代办事项表,减库存
        ItripTradeEnds itripTradeEnds =new ItripTradeEnds();
        itripTradeEnds.setId(order.getId());
        itripTradeEnds.setOrderNo(order.getOrderNo());
        itripTradeEnds.setFlag(0);
        itripTradeEndsMapper.insertItripTradeEnds(itripTradeEnds);
    }
}
